<template>
  <div>
    <el-table :data="orders" style="width: 100%">
      <el-table-column property="pid" label="订单编号" width="120"></el-table-column>
      <el-table-column property="users.uname" label="用户名称" width="120"></el-table-column>
      <el-table-column property="sumPrice" label="总价格"></el-table-column>
      <el-table-column property="orderDate" label="订单时间"></el-table-column>

      <el-table-column label="订单状态">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.orderState=='o-2'">待提货</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="货物状态">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.goodsState=='g-4'">等待用户提货</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="查看订单详情">
        <template slot-scope="scope">
          <el-link
            type="primary"
            @click="getOrderdetail(scope.row)"
          >查看详情
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot="header" slot-scope="scope">
          <el-button icon="el-icon-refresh-right" circle @click="c"></el-button>
        </template>
        <template slot-scope="scope">
          <el-button
            round
            type="primary"
            plain
          @click="updateState(scope.row)">确认提货</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageno"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <div>
      <component ref="view" is="orders_view_details"></component>
    </div>
  </div>
</template>

<script>
  import orders_view_details from "./orders_view_details";
    export default {
        name: "ordersCarryFreight",
      data(){
          return{
            orders:[],
            orderState:'o-2',
            goodsState:'g-4',
            pageno: 1,
            pagesize: 5,
            total: 1
          }
      },
      methods:{
          getdataordersCarryFreight(){
            var obj={
              pageno:this.pageno,
              pagesize:this.pagesize,
              orderState:this.orderState,
              goodsState:this.goodsState,
              loginUserId:sessionStorage.getItem("id")
            }
            this.$axios.get("QuerypartOrders.action",{params:obj}).then(res=>{
              this.orders=res.data.records;
              this.total=res.data.total;
            }).catch(error=>{
              this.$message.error(error)
            })
          },
        handleSizeChange(val) {
          //每页范围
          this.pagesize = val;
          this.getdataordersCarryFreight();
        },
        handleCurrentChange(val) {
          //当前页
          this.pageno = val;
          this.getdataordersCarryFreight();
        },
        getOrderdetail(row){
          this.$refs.view.dialogTableVisible=true;
          this.$refs.view.Orderdetails.pId=row.id
          this.$refs.view.getOrderdetailDetails()
        },
        updateState(row){
          this.$axios.put("updateOrders.action/"+row.id).then(res=>{
            if (res.data.code>0){
              this.$message.success(res.data.msg);
              this.getdataordersCarryFreight();
            }else {
              this.$message.error(res.data.msg)
            }
          }).catch(error=>{
            this.$message.error(error)
          })
        },
        c(){
            this.getdataordersCarryFreight()
        }
      },
      created() {
          this.getdataordersCarryFreight()
      },
      components:{
        orders_view_details
      }
    }
</script>

<style scoped>

</style>
